import { defineStore } from "pinia";
import { Topology } from "@topology/core";
interface UrlQueryParams {
  planNo?: string,
  storeNo?: string,
  storeName?: string,
  planType?: '0'|'1',
  sectionName?: string
}
interface RulerConfig {
	rulerSize: number;
	minSpace: number; 
	maxScaleVal: number;
	section: number;
	midDivision: number;
}
const useCommon = defineStore("common", {
	// 推荐使用 完整类型推断的箭头函数
	state: (): {
		urlQueryParams: UrlQueryParams;
		scaleRatio: number;
		preViewScaleRatio: number;
		rulerConfig: RulerConfig
	} => {
		return {
			urlQueryParams: {},
			scaleRatio: 100,
			preViewScaleRatio: 100,
			rulerConfig: {
				rulerSize: 30,
				midDivision: 10, // 一个刻度代表10cm
				minSpace: 5, // 单位刻度间距 50px = 100cm
				maxScaleVal: 1000, // 最大刻度尺刻度 单位米
				section: 1, // 段距 单位米
			}
		};
	},
	getters: {
		getUrlQueryParams: (state) => state.urlQueryParams,
		getScaleRatio: (state) => state.scaleRatio / 100 
	},
	actions: {
		changeUrlQueryParams(data: UrlQueryParams) {
			this.urlQueryParams = {...this.urlQueryParams, ...data};
		},
		changeRulerConfig(data: Partial<RulerConfig>) {
			this.rulerConfig = {...this.rulerConfig, ...data}
		}
	},
});
export default useCommon;
